$(function() {
//check_pass
  var pwd = new Vue({
    el:"#password_form",
    data:{
      userPassword:"",
      userNewPassword:"",
      check_pass:""
    },
    methods:{
      checkPwd:function () {
        var that = this;
        $('#password-notif').val('');
        if (that.userPassword=="" || that.userPassword==undefined){
          $('#password-notif').val('原密码不能为空');
          return false;
        }
        axios.post("../api/user/checkPwd",{
          userPassword:that.userPassword
        },{headers:{'token':localStorage.getItem('token')}}).then(function(response){
          if (response.data.code!="0"){
            alert(response.data.msg)
            return
          }
          $('#password-notif').val('原密码正确');
        }).catch(function(err){
          console.log(err);
        });
      },
      updatePwd:function () {
        var that = this;
        $('#password-notif').val('');
        if (that.userPassword=="" || that.userPassword==undefined){
          $('#password-notif').val('原密码不能为空');
          return false;
        }
        if (that.userNewPassword=="" || that.userNewPassword == undefined){
          $('#password-notif').val('新密码不能为空');
          return false;
        }
        if (that.check_pass == "" || that.check_pass == undefined){
          $('#password-notif').val('确认密码不能为空');
          return false;
        }
        if (that.check_pass != that.userNewPassword){
          $('#password-notif').val('两次密码不相同');
          return false;
        }
        if (that.userPassword == that.userNewPassword){
          $('#password-notif').val('新密码不能与原密码相同');
          return false;
        }
        axios.post("../api/user/updatePwd",{
          userNewPassword:that.userNewPassword,
          userPassword:that.userPassword
        },{headers:{'token':localStorage.getItem('token')}}).then(function(response){
          if (response.data.code!="0"){
            alert(response.data.msg)
            return
          }
          alert("修改密码成功,请重新登录");
          that.id = "";
          that.userNewPassword="";
          that.userPassword="";
          location.href = "login.html";
        }).catch(function(err){
          console.log(err);
        });
      }
    }
  })

  var getTokenVue = new Vue({
    el:"#getToken",
    data:{
      token:localStorage.getItem("token")
    }
    ,methods:{

    }
  })
});